﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading.Tasks;
using System.Diagnostics;
using Hydra.Shell.Interfaces;
using Hydra.Shell.Implementations;
using SLControlLibrary;

namespace TestClientPackage
{
    public partial class MainPage : UserControl
    {
        private WeakReference reference;

        public MainPage()
        {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            TestDisposal();
            TestWrap();
        }

        private void TestWrap()
        {
            var myService = (IUnknown) new MyService();
        }

        private void TestDisposal()
        {
            var task = new Task(() =>
            {
                var package = new MyPackage(new UIThread(this.Dispatcher));

                package.Disposed += new EventHandler(PackageDisposed);

                reference = new WeakReference(package, false);
            });

            task.Start();
        }


        private void PackageDisposed(object sender, EventArgs e)
        {
            Debugger.Break();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            var array = new byte[25000000];

            GC.Collect();
        }
    }
}
